package org.example.rzfx.controller;

import org.example.rzfx.dto.Result;
import org.example.rzfx.entity.CollectMonitor;
import org.example.rzfx.service.CollectMonitorService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 监控控制器
 */
@RestController
@RequestMapping("/api/monitor")
@CrossOrigin
public class MonitorController {
    
    @Resource
    private CollectMonitorService collectMonitorService;
    
    /**
     * 查询所有采集监控数据
     */
    @GetMapping("/list")
    public Result<List<CollectMonitor>> listMonitors() {
        return Result.success(collectMonitorService.list());
    }
    
    /**
     * 根据采集源ID查询监控数据
     */
    @GetMapping("/source/{sourceId}")
    public Result<CollectMonitor> getMonitorBySource(@PathVariable Long sourceId) {
        CollectMonitor monitor = collectMonitorService.getOrCreateMonitor(sourceId);
        return Result.success(monitor);
    }
}

